<?php
require_once('start_session.php');

// header
require_once("header.php");
require_once('db_connect.php');
require_once('global_vars.php');
require_once('search_bar.php');
require_once('connect_info.php');
//require_once('survey_list.php');
if (isset($_COOKIE['user_id']) && $_COOKIE['user_id'] != ADMIN_ID)
	require_once('member_info.php');
	
/*	
echo $_COOKIE['user_id'];
echo $_SESSION['ip'];
echo $_SESSION['connect_time'];
*/
//require_once("member_info.php");
// footer
?>
<div id="participate_main_div" style='text-align:center;height:400px'>
<?php

$answer_ip = $_SESSION['ip'];
$answer_connect_time = $_SESSION['connect_time'];
$answer_user_id = $_COOKIE['user_id'];

/*
echo "answer_ip = $_POST[answer_ip]<br>";
echo "answer_connect_time = $_POST[connect_time]<br>";
echo "answer_survey_id = $_POST[answer_survey_id]<br>";
echo "answer_gender = $_POST[answer_gender]<br>";
echo "answer_edulevel = $_POST[answer_edulevel]<br>";
echo "answer_age = $_POST[answer_age]<br>";
echo "answer_addr = $_POST[answer_addr]<br>";
*/

//$result = mysqli_query($conn, "insert into answer values('select * from keyword_survey where survey_id = '$survey_row[id]'");

$sql = "insert into answer values('$answer_ip', '$answer_connect_time', '$_POST[answer_survey_id]', now(), '$answer_user_id', '$_POST[answer_gender]', '$_POST[answer_edulevel]', '$_POST[answer_age]', '$_POST[answer_addr]')";
//echo $sql."<br />";
$result = mysqli_query($conn, $sql);

if($answer_user_id != '')
{
	mysqli_query($conn, "update member set answer_count = answer_count + 1 where id = '$answer_user_id'");
}

if(!$result)
{
	echo "[sql실패]<br />";
}

//echo "<br>";


$i = 0;
foreach($_POST as $key=>$val)
{
	$i++;
	if($i > 7)
	{
		$a = explode('_', $key);
		$qnum = $a[0];
		if($a[1] == '')
		{
			$inum = $val;
		}
		else
		{
			$inum = $a[1];
		}
//		echo "$qnum -> $inum<br>";
		
		$sql = "insert into result values('$answer_ip', '$answer_connect_time', '$_POST[answer_survey_id]', '$qnum', '$inum')";
//		echo $sql."<br />";
		$result = mysqli_query($conn, $sql);
		if(!$result)
		{
			echo "[sql실패]<br />";
		}
	}
}
?>


<br /><br /><br />
설문에 참여해주셔서 감사합니다!<br /><br />
<font style='font-size:12px'>2초후 메인페이지로 이동합니다.</font><br><br>
<a href=main.php><u>지금 메인페이지로 이동</u></a><br>

<meta http-equiv="refresh" content="2;url=main.php">

</div>

<?php
mysqli_close($conn);
require_once("footer.php");
?>

